Skip to content

Conversation

@arcanis
Copy link
Member

@arcanis arcanis commented Jun 25, 2025

The regex crate is making the library fairly large. Since we also use fancy_regex, having regex feels redundant. We only need it for its ability to operate over slices rather than just str, but with some refactoring of the vpath function I managed to avoid it entirely, making it possible to remove the dependency.

Along with disabling unicode support for fancy_regex, we get a ~1,7MiB binary (-1MiB). The remaining report shows that fancy_regex is now the main overhead, but unfortunately I don't see a good way to fix it without removing support for pnpIgnorePattern (which is stored as a regex inside the JSON payload):

 File  .text     Size Crate
18.4%  33.9% 313.2KiB std
15.4%  28.4% 262.5KiB regex_automata
 9.8%  18.1% 167.0KiB regex_syntax
 6.0%  11.0% 101.8KiB pnp
 3.4%   6.3%  58.3KiB fancy_regex
 0.8%   1.4%  12.9KiB serde_json
 0.2%   0.4%   3.9KiB serde
 0.2%   0.3%   2.8KiB [Unknown]
 0.2%   0.3%   2.7KiB ryu
 0.1%   0.2%   2.0KiB smallvec
 0.1%   0.2%   2.0KiB hashbrown
 0.1%   0.1%   1.3KiB pathdiff
 0.1%   0.1%   1.3KiB radix_trie
 0.0%   0.1%     792B clean_path
 0.0%   0.0%      20B __rustc
 0.0%   0.0%      12B path_slash
54.3% 100.0% 924.3KiB .text section size, the file size is 1.7MiB

Ref unrs/unrs-resolver#166

lazy_static! {
static ref VIRTUAL_RE: Regex
= Regex::new(
"(?:^|/)((?:\\$\\$virtual|__virtual__)/(?:[^/]+)-[a-f0-9]+/([0-9]+)/)"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed support for the $$virtual pattern. We stopped generating it in Yarn 3.X a couple of years ago (it was making weird things when people passed paths as second parameter of String.prototype.replace), so this shouldn't be an issue.

@arcanis arcanis merged commit f0e0861 into main Jun 26, 2025
1 check passed
let mut base_path_u8 = archive_path_u8;
let mut virtual_segments = None;

if let Some((mut virtual_len, parent_depth)) = virtual_path_u8 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In rspack-resolver's benchmark, the regex is faster in no-virtual no-zip path.
Maybe keeping the regex implimentation but using fancy-regex is an optimal way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants